package com.qzh.baseStruct.Graph;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 图节点
 */
public class GraphNode {
    /**
     * 值
     */
    private Object value;
    /**
     * 节点id
     */
    private final long id;

    public Map<Long, InnerLine> getLinked() {
        return linked;
    }

    /**
     * 相邻的节点与权重值
     */
    private final Map<Long,InnerLine> linked;








    public GraphNode(long id){
        this.linked = new HashMap<>();
        this.id = id;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    /**
     * 添加链接
     * @param id
     */
    public void  addLink(long id,BigDecimal weight,LineType type){
        InnerLine innerLine = new InnerLine();
        innerLine.setLineType(type);
        innerLine.setWeight(weight);
        this.linked.put(id,innerLine);
    }

    /**
     * 删除链接
     * @param id
     */
    public void removeLink(long id){
        this.linked.remove(id);
    }

    /**
     * 根据id获取权重值
     * @param id
     * @return
     */
    public BigDecimal getWeightFromNodeId(long id){
        return this.linked.get(id).getWeight();
    }

    public long getId() {
        return id;
    }

    /**
     * 线，weight为权重，type为线类型
     */
    public class InnerLine {
        private BigDecimal weight;
        public LineType lineType;

        public BigDecimal getWeight() {
            return weight;
        }

        public void setWeight(BigDecimal weight) {
            this.weight = weight;
        }

        public LineType getLineType() {
            return lineType;
        }

        public void setLineType(LineType lineType) {
            this.lineType = lineType;
        }
    }
    public enum LineType{
        /**
         * normal为双向同行
         */
        normal,
        /**
         * 只能出发，无法到达
         */
        onlySrart,
        /**
         * 只能到达，无法出发
         */
        onlyEnd,
        /**
         * banned为禁止通行
         */
        banned
    }
}
